/*
 * Vector.java
 *
 * Created on December 3, 2007, 1:11 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package simfinal;

import com.jme.math.Vector3f;

/**
 *
 * @author jkeister
 */
public class Vector 
{
    double[] data;
    
    /**
     * Creates a new instance of Vector
     */
    public Vector() 
    {
        data = new double[3];
        for(int i=0; i<3; ++i) data[i] = 0.0;
    }

   public void set(double a, double b, double c)
   {
      data[0] = a;
      data[1] = b;
      data[2] = c;
   }

   public Vector(double a, double b, double c)
   {
      this();
      data[0] = a;
      data[1] = b;
      data[2] = c;
   }

   public Vector(Vector a)
   {
      this();
      set(a);
   }

   public void set(Vector x)
   {
      for(int i=0; i<3; ++i) data[i] = x.data[i];
   }

   public void add(Vector x)
   {
      for(int i=0; i<3; ++i) data[i] += x.data[i];
   }

   public void addm(Vector x, double m)
   {
      for(int i=0; i<3; ++i) data[i] += x.data[i]*m;
   }

   public void madd(double m, Vector x)
   {
      for(int i=0; i<3; ++i)
      {
         data[i] *= m;
         data[i] += x.data[i];
      }
   }

   public void maddv(double m, Vector x, double m2)
   {
      for(int i=0; i<3; ++i)
      {
         data[i] *= m;
         data[i] += x.data[i]/m2;
      }
   }

   public void maddm(double m, Vector x, double m2)
   {
      for(int i=0; i<3; ++i)
      {
         data[i] *= m;
         data[i] += x.data[i]*m2;
      }
   }

   public void sub(Vector x)
   {
      for(int i=0; i<3; ++i) data[i] -= x.data[i];
   }

   public void mult(double x)
   {
      for(int i=0; i<3; ++i) data[i] *= x;
   }

   public void div(double x)
   {
      for(int i=0; i<3; ++i) data[i] /= x;
   }

   public double dot(Vector x)
   {
      double v = 0;
      for(int i=0; i<3; ++i) v+= data[i]*x.data[i];
      return v;
   }
   
   public Vector3f toVector3f()
   {
       Vector3f v3f = new Vector3f((float)data[0],(float)data[1],(float)data[2]);
       return v3f;
   }
}